package com.cr.manager.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.cr.manager.domain.dto.UserRentDto;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.cr.common.annotation.Log;
import com.cr.common.core.controller.BaseController;
import com.cr.common.core.domain.AjaxResult;
import com.cr.common.enums.BusinessType;
import com.cr.manager.domain.UserRent;
import com.cr.manager.service.IUserRentService;
import com.cr.common.utils.poi.ExcelUtil;
import com.cr.common.core.page.TableDataInfo;

/**
 * 车辆租借管理Controller
 * 
 * @author lms
 * @date 2024-08-07
 */
@RestController
@RequestMapping("/manager/userRent")
public class UserRentController extends BaseController
{
    @Autowired
    private IUserRentService userRentService;

    /**
     * 查询车辆租借管理列表
     */
    @PreAuthorize("@ss.hasPermi('manager:userRent:list')")
    @GetMapping("/list")
    public TableDataInfo list(UserRentDto userRentDto)
    {
        startPage();
        List<UserRentDto> list = userRentService.selectUserRentList(userRentDto);
        return getDataTable(list);
    }

    /**
     * 导出车辆租借管理列表
     */
    @PreAuthorize("@ss.hasPermi('manager:userRent:export')")
    @Log(title = "车辆租借管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, UserRentDto userRentDto)
    {
        List<UserRentDto> list = userRentService.selectUserRentList(userRentDto);
        ExcelUtil<UserRentDto> util = new ExcelUtil<UserRentDto>(UserRentDto.class);
        util.exportExcel(response, list, "车辆租借管理数据");
    }

    /**
     * 获取车辆租借管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('manager:userRent:query')")
    @GetMapping(value = "/{userId}")
    public AjaxResult getInfo(@PathVariable("userId") String userId)
    {
        return success(userRentService.selectUserRentByUserId(userId));
    }

    /**
     * 新增车辆租借管理
     */
    @PreAuthorize("@ss.hasPermi('manager:userRent:add')")
    @Log(title = "车辆租借管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody UserRent userRent)
    {
        return toAjax(userRentService.insertUserRent(userRent));
    }

    /**
     * 修改车辆租借管理
     */
    @PreAuthorize("@ss.hasPermi('manager:userRent:edit')")
    @Log(title = "车辆租借管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody UserRent userRent)
    {
        return toAjax(userRentService.updateUserRent(userRent));
    }

    /**
     * 删除车辆租借管理
     */
    @PreAuthorize("@ss.hasPermi('manager:userRent:remove')")
    @Log(title = "车辆租借管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{userIds}")
    public AjaxResult remove(@PathVariable String[] userIds)
    {
        return toAjax(userRentService.deleteUserRentByUserIds(userIds));
    }
}
